package net.oschina.app.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.bean.ActiveBean;
import net.oschina.app.util.CommonUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by elf on 2017/1/18.
 */
public class DetailCommentFragment extends Fragment {
    @BindView(R.id.iv_icont)
    CircleImageView mIvIcont;
    @BindView(R.id.tv_name)
    TextView mTvName;
    @BindView(R.id.tv_time)
    TextView mTvTime;
    @BindView(R.id.tv_des1)
    TextView mTvDes1;
    @BindView(R.id.tv_praisecount1)
    TextView mTvPraisecount1;
    @BindView(R.id.tv_commentcount1)
    TextView mTvCommentcount1;
    @BindView(R.id.tv_des2)
    TextView mTvDes2;
    @BindView(R.id.ll_likelist)
    LinearLayout mLlLikelist;
    @BindView(R.id.lv_comment)
    ListView mLvComment;
    @BindView(R.id.et_comment)
    EditText mEtComment;
    @BindView(R.id.iv_emoji)
    ImageView mIvEmoji;
    @BindView(R.id.iv_send)
    ImageView mIvSend;
    @BindView(R.id.gv_emoji)
    GridView mGvEmoji;
    private ActiveBean mActiveBean;
    private int objectId ;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View itemView = LayoutInflater.from(CommonUtils.getContext()).inflate(R.layout.comment_detail, container, false);
        ButterKnife.bind(this, itemView);
        Bundle arguments = getArguments();
        mActiveBean = (ActiveBean) arguments.get("commentbean");
        initData();
        return itemView;
    }

    private void initData() {
        mTvName.setText(mActiveBean.getObjectreply().getObjectname());
        mTvDes1.setText(mActiveBean.getObjectreply().getObjectbody());
        objectId = mActiveBean.getObjectID();
        ListViewAdapter listViewAdapter = new ListViewAdapter();
        mLvComment.setAdapter(listViewAdapter);
    }

    class ListViewAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return 1;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder viewHolder = null;
            if (view == null) {
                viewHolder = new ViewHolder();
                view = View.inflate(CommonUtils.getContext(), R.layout.item_comment_detail, null);
                view.setTag(viewHolder);
                viewHolder.mIvIcontDetail = (CircleImageView) view.findViewById(R.id.iv_icont_detail);
                viewHolder.mTvUserNameDetail = (TextView) view.findViewById(R.id.tv_user_name_detail);
                viewHolder.mTvDateDetail = (TextView) view.findViewById(R.id.tv_date_detail);
                viewHolder.mTvMsgDetail = (TextView) view.findViewById(R.id.tv_msg_detail);
            } else {
                viewHolder = (ViewHolder) view.getTag();
            }
            Glide.with(CommonUtils.getContext()).load(mActiveBean.getPortrait()).into(viewHolder.mIvIcontDetail);
            viewHolder.mTvUserNameDetail.setText(mActiveBean.getAuthor());
            viewHolder.mTvDateDetail.setText(mActiveBean.getPubDate());
            viewHolder.mTvMsgDetail.setText(mActiveBean.getMessage());
            return view;
        }


        class ViewHolder {
            CircleImageView mIvIcontDetail;
            TextView mTvUserNameDetail;
            TextView mTvDateDetail;
            TextView mTvMsgDetail;
        }
    }
}
